package com.tedu.startbooksstore.service.impl;

import com.tedu.startbooksstore.ex.ServiceException;
import com.tedu.startbooksstore.mapper.BannerMapper;
import com.tedu.startbooksstore.pojo.vo.BannerListItemVO;
import com.tedu.startbooksstore.service.IBannerService;
import com.tedu.startbooksstore.web.ServiceCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 轮播图接口实现类
 * @author 敖朝浪
 */
@Slf4j
@Service
public class BannerServiceImpl implements IBannerService {

    @Autowired
    BannerMapper bannerMapper;


    @Override
    public void deleteById(Long id) {
        log.debug("开始处理删除轮播图业务,参数:{}",id);
        //通过id查询轮播图是否存在
        int count = bannerMapper.countById(id);
        //轮播图不存在
        if (count==0){
            String message="删除失败,轮播图不存在";
            throw new ServiceException(ServiceCode.ERR_NOT_FOUND,message);
        }
        //删除轮播图
        bannerMapper.deleteById(id);
        log.debug("删除成功");
    }

    /**
     * 轮播图的列表
     * @return
     */
    @Override
    public List<BannerListItemVO> list() {
        log.debug("开始处理轮播图列表业务");
       return bannerMapper.list();
    }
}
